﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace ValidationFramework.WPF
{
	/// <summary>
	/// The <see cref="IErrorDisplayStrategy"/> for <see cref="RadioButton"/>s.
	/// </summary>
	/// <remarks>
	/// Will show and hide a <see cref="FrameworkElement"/>s <see cref="Validation.ErrorTemplateProperty"/>.
	/// </remarks>
	public class RadioButtonErrorDisplayStrategy : ErrorDisplayStrategy
	{
		/// <inheritdoc />
        public override bool CanHandleTarget(FrameworkElement frameworkElement)
        {
            return frameworkElement is RadioButton;
        }


		/// <inheritdoc />
		public override void DisplayError(BindingExpressionBase bindingExpressionBase, FrameworkElement frameworkElement, string errorMessage)
		{
			var parent = (FrameworkElement) frameworkElement.Parent;
			DisplayToolTip(parent, errorMessage);
			DisplayValidationAdorner(parent);
		}

		/// <inheritdoc />
		public override void ClearError(FrameworkElement frameworkElement)
		{
			var parent = (FrameworkElement)frameworkElement.Parent;
			ClearToolTip(parent);
			ClearValidationAdorner(parent);
		}

	

	}
}
